package com.jr.dao.impl;

import com.jr.dao.UserDao;
import com.jr.entry.User;
import com.jr.util.DBHelper;

public class UserDaoImpl implements UserDao {
    String sql ;
    DBHelper db = new DBHelper();
    @Override
    public boolean selectUserByAccountAndPassword(String account, String password) {
        sql = "select * from user where account = ? and password =? ";

        return(db.query(sql,User.class,account,password).size())!=0?true:false;
    }

    @Override
    public boolean updateUser(String idcardName, String idcardNo, String account,String name) {
        sql = "update user set idcardName = ? ,idcardNo = ? ,enterpriseName = ? where account=? ";
        System.out.println(idcardName+".....updateuser");
        System.out.println(idcardNo+".....updateuser");
        return db.updateTable(sql,idcardName,idcardNo,name,account)!=0?true:false;
    }

    @Override
    public User selectUserByAccount(String account) {
        sql = "select * from user where account = ? ";
        return (User)(db.query(sql,User.class,account).get(0));
    }

    @Override
    public User selectUserByEnterpriseId(String enterpriseId) {
        sql = "select * from user where enterpriseId = ? ";
        return  (User)(db.query(sql,User.class,enterpriseId).get(0));
    }

    @Override
    public boolean updateUserEnterpriseIdAndName(String account, String enterpriseId, String enterpriseName) {
        String sql="update user set enterpriseId=? , enterpriseName=? where account = ? ";
        return db.updateTable(sql,enterpriseId,enterpriseName,account)>0?true:false;
    }


}
